<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            width: 400px;
            min-height: 100px;
            border: 2px dotted red;
        }
    </style>
</head>

<body>
    <button>获取彩票信息</button>
    <div></div>
    <script>
        var oBtn = document.querySelector('button');
        var oDiv = document.querySelector('div');
        oBtn.onclick = function () {
            //获取随机数 7位 1-34 
            var caipiao = getRandom(7, 1, 34);
            console.log(caipiao);

            //将彩票信息保存到历史记录里
            //用hash保存彩票信息
            location.hash = caipiao;
            console.log(location);
            //显示在页面上
            oDiv.innerHTML = caipiao;
        }

        //绑定 历史记录发生变化就会触发的事件
        window.onhashchange = function (ev) {
            console.log(location.hash);
            oDiv.innerHTML = location.hash.substring(1);
        }


        function getRandom(count, start, end) {
            var numArr = [];
            for (var i = 0; i < count; i++) {
                var num1 = Math.floor(Math.random() * (end - start) + start);
                numArr.push(num1);
            }
            return numArr;
        }

    </script>
</body>

</html>